package com.example.apidocserver.infrastructure.aop;

import com.example.apidocserver.infrastructure.constants.SystemConstants;
import com.example.apidocserver.infrastructure.util.user.UserUtil;
import com.example.apidocserver.infrastructure.util.result.ParamException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 权限切面
 *
 * @author xyqlg
 */
@Aspect
@Component
@Slf4j
public class PermissionsAop {
    @Pointcut("@annotation(com.example.apidocserver.infrastructure.aop.PermissionAnno)")
    public void brokerAspect() {
    }

    @Around("brokerAspect()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        if (UserUtil.isTourists()) {
            throw new ParamException(SystemConstants.NO_AUTHO);
        }
        Object proceed = joinPoint.proceed();
        log.info("正在执行的目标方法是: {}", joinPoint.getSignature().getName());
        return proceed;
    }

}